<template>
  <div style="background-color: yellow;width: 700px;height: 500px">
    <el-button type="primary" @click="clickDown()">Primary</el-button>
  </div>
</template>

<script lang="ts" setup>
import {handleTree} from '../utils/ruoyi'
import { getMedia } from 'api/myfile'
function clickDown(){
  getMedia({
    'mediaId':'WWME_AR2BDwAA3J-4mYukq8UiNdVvlLusng'
  }).then(response=>{
    const headers = response.headers
    let fileName = 'download.bin'
    // 解析文件名
    const disposition = headers['content-disposition']
    console.log(disposition)
    if (disposition) {
      const fileNameMatch = disposition.match(/filename\*?=(?:UTF-8'')?["']?([^;"']+)["']?/)
      if (fileNameMatch && fileNameMatch.length > 1) {
        fileName = decodeURIComponent(fileNameMatch[1])
      }
    }
    // 创建 Blob
    const blob = new Blob([response.data])
    // 创建临时 <a> 下载
    const link = document.createElement('a')
    link.href = window.URL.createObjectURL(blob)
    link.download = fileName
    link.click()

    // 释放 URL
    window.URL.revokeObjectURL(link.href)
  })
}
const test1="WWME_AR2BDwAApD5y1y0ATOayMrxJfYoiuA"
const test2 = "WWME_AR2BDwAA3J-4mYukq8UiNdVvlLusng"
</script>